/* util */
import { storageGet } from '@src/util/storage.js'

type IMInitDataType = {
  // 客服机器人 灰度
  customerServiceRobot: boolean;
  // 视频客服 灰度
  openVideoCallService: boolean;
  // 微信服务 灰度
  openWeChatService: boolean;
}

const DefaultIMInitData: IMInitDataType = {
  customerServiceRobot: false,
  openVideoCallService: false,
  openWeChatService: false
}

const IMInitDataStorageKey = 'im_initData'
const IMIsOpenStorageKey = 'im_isOpen'

/** 
 * @description 获取im是否开启
*/
export function getIMIsOpen(): boolean {
  return storageGet(IMIsOpenStorageKey) == 1
}

/** 
 * @description 获取IM初始化数据
*/
export function getIMInitData(): Partial<IMInitDataType> {
  
  try {
    
    const storageData = storageGet(IMInitDataStorageKey)
    
    return JSON.parse(storageData) || DefaultIMInitData
    
  } catch (error) {
    return DefaultIMInitData
  }
  
}

export default {
  getIMInitData,
  getIMIsOpen
}